package ch.ti.bfh.app.loodel.internal.repository;

import org.springframework.data.jpa.repository.support.JpaEntityInformation;
import org.springframework.data.jpa.repository.support.QueryDslJpaRepository;

import javax.persistence.EntityManager;
import javax.persistence.EntityNotFoundException;
import java.io.Serializable;

public class DefaultGlobalRepository<T, ID extends Serializable> extends QueryDslJpaRepository<T, ID> implements GlobalRepository<T, ID> {

    private EntityManager entityManager;

    public DefaultGlobalRepository(JpaEntityInformation<T, ID> entityInformation, EntityManager entityManager) {
        super(entityInformation, entityManager);
        this.entityManager = entityManager;
    }

    @Override
    public T getOne(ID id) {
        T one = super.findOne(id);
        if (one == null) {
            throw new EntityNotFoundException("No Entity found for id:'" + id + "'");
        }
        return one;
    }
}